import React from "react";
import './TodoMain.css';
import store from "../../../redux/store";
import { asyncCheckTodoAction, asyncRemoveTodoAction, checkTodoAction, removeTodoAction } from "../../../redux/reducers/todoReducer";

export default function TodoMain() {
  return (
    <ul className="todo-main">
      { 
        store.getState().todo.map(item => {
          return <li key={item.id}>
                  <label>
                    <input type="checkbox" checked={item.done} onChange={(e) => {
                      store.dispatch(asyncCheckTodoAction(item.id, e.target.checked));
                    }} />
                    <span className={item.done ? 'done' : ''}>{item.title}</span>
                  </label>
                  <button className="btn btn-danger" onClick={() => {
                    store.dispatch(asyncRemoveTodoAction(item.id))
                  }}>删除</button>
                </li>
        })
      }
    </ul>
  );
}
